﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using ArgusLib.Xml;

namespace Fraktalysator
{
	class UIMemory
	{
		public ToolStrip ToolStripFile { get; set; }
		public ToolStrip ToolStripEdit { get; set; }
		public ToolStrip ToolStripToolTip { get; set; }
		public ToolStrip ToolStripStatus { get; set; }
		public Form FormFractalParameter { get; set; }
		public Form FormRendererParameter { get; set; }
		public Form FormImage { get; set; }
		public Form FormPreviewImage { get; set; }
		public Form FormMainWindow { get; set; }
		public string FilenameSaveFileDialog { get; set; }
		public string FilenameOpenFileDialog { get; set; }
		public bool CheckForUpdates { get; set; }

		public UIMemory()
		{ }

		public static UIMemory Load()
		{
			if (File.Exists(FileSystem.FileUIMemory) == false)
				return null;

			using (FileStream file = new FileStream(FileSystem.FileUIMemory, FileMode.Open))
			{
				using (Deserializer des = Deserializer.FromStream(file))
				{
					return des.Deserialize() as UIMemory;
				}
			}
		}

		public static void Save(UIMemory uiMemory)
		{
			using (FileStream file = new FileStream(FileSystem.FileUIMemory, FileMode.Create))
			{
				using (Serializer ser = Serializer.FromStream(file, "UserData"))
				{
					ser.Serialize(uiMemory);
				}
			}
		}

		public struct ToolStrip
		{
			public string Parent { get; set; }
			public Point Location { get; set; }

			public ToolStrip(System.Windows.Forms.ToolStrip toolStrip)
				: this()
			{
				this.Parent = toolStrip.Parent.Name;
				this.Location = toolStrip.Location;
			}

			public void Set(System.Windows.Forms.ToolStrip toolStrip, System.Windows.Forms.Form form)
			{
				toolStrip.Parent = form.Controls[this.Parent];
				toolStrip.Location = this.Location;
			}
		}

		public struct Form
		{
			public Point Location { get; set; }
			public Size Size { get; set; }

			public Form(System.Windows.Forms.Form form)
				: this()
			{
				this.Location = form.Location;
				this.Size = form.Size;
			}

			public void Set(System.Windows.Forms.Form form)
			{
				form.Location = this.Location;
				form.Size = this.Size;
			}
		}

		public struct ToolForm
		{
			public Point Location { get; set; }
			public Size Size { get; set; }
			public bool Visible { get; set; }

			public ToolForm(System.Windows.Forms.Form form)
				: this()
			{
				this.Location = form.Location;
				this.Size = form.Size;
				this.Visible = form.Visible;
			}

			public void Set(System.Windows.Forms.Form form)
			{
				form.Location = this.Location;
				form.Size = this.Size;
				form.Visible = this.Visible;
			}
		}
	}
}
